import {companyInfo} from '../../api/info'

const storage = window.localStorage
const user = {
  state: {
    data: {},
    // compangTelephone:"",  // 固定电话
    //   numberQq:"",  // qq号
    //   companyIntroduce:"",
    //   compangMobile:"",
    //   companyFax:'', // 传真
    //   companyEmail:"",
    //   companyUrl:"",
    //   address:"",
    userInfo: {name: '千城月下'}, // 用户信息
    isLogin: false, // 登录状态
    showLogin: false, // 显示登录框
  },
  getters: {
    userInfo: state => {
    
      let data = JSON.parse(storage.getItem('userInfo'))
      if (data) {
      
        state.userInfo = data
      }
      return state.userInfo
    },
    isLogin: state => {
    
      let data = JSON.parse(storage.getItem('isLogin'))
      if (data) {
        state.isLogin = data
      }
      return state.isLogin
    },
    showLogin: state => {
      return state.showLogin
    }
  },
  mutations: {
    // 更新用户信息  userInfo  存储到浏览器缓存 写入登录状态
    updateUserInfoData(state, data) {

   
      state.userInfo = data
      storage.setItem('userInfo', data)
      if(data){
        state.isLogin = true
        storage.setItem('isLogin', true)
      }else {
        state.isLogin = false
        storage.setItem('isLogin', false)
      }
    },
    GET_INFO(state, datas) {
      state.data = datas
      // console.log( state.data)
    },
    updateShowLoginData(state, data) {
      state.showLogin = data
    },
  },

  actions: {
    get_info({commit}) {
      companyInfo().then(res => {
        let datas = res.data
        commit('GET_INFO', datas)
      })
    }

  }
}

export default user
